package cs.model;

import java.util.ArrayList;
import java.util.Observable;

import cs.entity.UserFile;

/**
 * This class represents a received file messages queue by the network.<p>
 * Package  cs.model
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 */
public class ReceivedFileModel extends Observable{
	/**
	 * the received file manager
	 */
	private ArrayList<UserFile> receivedFile;
	
	/**
	 * constructor
	 */
	public ReceivedFileModel(){
		receivedFile = new ArrayList<UserFile>();
	}
	
	/**
	 * add a new file to the model
	 * @param file the file to add
	 */
	public void addReceivedFile(UserFile file){
		receivedFile.add(file);
		setChanged();
		notifyObservers(file);
	}
	
	/**
	 * change the state of the file
	 * @param file which state is to be changed
	 * @param state the new state
	 */
	public UserFile setFileState(UserFile file, UserFile.State state){
		UserFile fichier = null;
		for(UserFile f : receivedFile){
			if(f.equals(file)){
				fichier = f;
				fichier.setState(state);
				setChanged();
				notifyObservers(fichier);
			}
		}
		return fichier;
		
	}
	/**
	 * remote the received file from the model
	 * @param file the file to remove
	 */
	public void removeFile(UserFile file){
		if(receivedFile.contains(file)){
			receivedFile.remove(file);
		}
		else{
			System.out.println("cannot remove file");
		}
	}
}
